package com;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class Th extends Thread {
	private Snake snake;
	private JPanel p1;
	private JLabel jl6;
	private JLabel jl4;

	public Th(Snake snake, JPanel p1, JLabel jl6, JLabel jl4) {
		super();
		this.snake = snake;
		this.p1 = p1;
		this.jl6 = jl6;
		this.jl4 = jl4;
	}

	public void run() {
		while (true) {
			if (snake.getState() == Snake.RUNNING) {
				snake.eat();
				snake.move();
				jl6.setText(String.valueOf(snake.score));
			} else if (snake.getState() == Snake.OVER) {
				jl4.setText("GameOver！");
				break;
			}
			p1.repaint();
			try {
				Thread.sleep(snake.speed);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
